# -*- coding: utf-8 -*-

# Author : 'hxc'

# Time: 2018/12/18 10:37 AM

# File_name: 'manage.py'

"""
Describe: this is a demo!
"""

import codecs
from ConsultAPI.conf import html_path
from ConsultAPI.combine import  Find_Difference
from ConsultAPI.ProposalAPI import DeleteFiles, Proposal

class Manage(object):
    """
    执行脚本
    """
    def __init__(self, html_source_path, uuid, pool):
        """
        构造实例化
        """
        self.uuid = uuid
        self.pool = pool
        self.html_source_path = html_source_path
        proposal = Proposal(self.uuid, self.pool)
        dispute_type_id, user_path, report_list = proposal.process_content()
        self.xml_file = proposal.xml_file_find(dispute_type_id)
        self.user_path = user_path
        self.report = report_list

    def return_report_string(self):
        """
        读取final.html文件，以str形式返回出去。
        :return:
        """
        report_generator = Find_Difference(self.xml_file, self.html_source_path, self.report, self.uuid, self.pool)
        report_generator.final_combine()
        with open('./ConsultAPI/final_combine/final.html', 'r', encoding='utf-8') as f:
            result_string = f.read()
        delete_file = DeleteFiles()
        # 删除暂存文件
        delete_file.delete_file('./ConsultAPI/final_combine/')
        delete_file.delete_file('./ConsultAPI/source_html/')
        delete_file.delete_file('./ConsultAPI/source_html_ex/')
        delete_file.delete_file('./ConsultAPI/tmp_combine/')
        return result_string


